home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / CDiscount (FR).ifs < prev    next >
Text File  |  2005-03-13  |  11KB  |  355 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Thierry Colier
  8. Title=CDiscount
  9. Description=CDiscount (FR) Descriptif et image
  10. Site=http://www.cdiscount.com
  11. Language=FR
  12. Version=
  13. Requires=3.5.0
  14. Comments=
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program CDISCOUNT_FR;
  23. var
  24.   MovieName: string;
  25.  
  26. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  27. var
  28.   i: Integer;
  29. begin
  30.   result := -1;
  31.   if StartAt < 0 then
  32.     StartAt := 0;
  33.   for i := StartAt to List.Count-1 do
  34.     if Pos(Pattern, List.GetString(i)) <> 0 then
  35.     begin
  36.       result := i;
  37.       Break;
  38.     end;
  39. end;
  40.  
  41. procedure RecupereGrandeImage (Adr : String);
  42. var
  43.    Page : TStringList;
  44.    Line, Value : string;
  45.    LineNr: Integer;
  46.    BeginPos : Integer;
  47. begin
  48.    HTMLDecode(Adr);
  49.    Page := TStringList.Create;
  50.    Page.Text := GetPage('http://www.cdiscount.com/newmag/mag_dvd/' + Adr);
  51.    
  52.    LineNr := FindLine('<img border="0" src="', Page, 0); 
  53.    if LineNR > -1 then
  54.    begin 
  55.       Line := Page.GetString(LineNr);
  56.       BeginPos := pos ('<img border="0" src="', Line);
  57.       Delete(Line, 1, BeginPos+20);
  58.       BeginPos := pos ('"></a>', Line);
  59.       value := copy (Line, 1, BeginPos - 1);
  60.       GetPicture(value); 
  61.    end;
  62. end;
  63.  
  64. procedure AnalyzeMoviePage(Page: TStringList);
  65. var
  66.   Line, Value, Value2 : string;
  67.   LineNr: Integer;
  68.   BeginPos, EndPos, valeur : Integer;
  69. begin
  70.    // Image
  71.    LineNr := FindLine('zoom_fiche.asp?rep=', Page, 0); // on rΘcupΦre la grande image s'il y en a une
  72.    if LineNR > -1 then
  73.    begin 
  74.       Line := Page.GetString(LineNr);
  75.       BeginPos := pos ('zoom_fiche.asp?rep=', Line);
  76.       Delete(Line, 1, BeginPos-1);
  77.       BeginPos := pos (',530,400,', Line);
  78.       value := copy (Line, 1, BeginPos - 10);
  79.       RecupereGrandeImage(Value);
  80.    end
  81.    else
  82.    begin
  83.       LineNr := FindLine('"#000000"><IMG border="0" src="', Page, 0);
  84.       if LineNr > -1 then
  85.       begin
  86.          Line := Page.GetString(LineNr);
  87.          BeginPos := pos ('"#000000"><IMG border="0" src="', Line);
  88.          Delete(Line, 1, BeginPos + 30);
  89.          BeginPos := pos ('"></TD></TR></TABLE>', Line);
  90.          value := copy (Line, 1, BeginPos - 1);
  91.          GetPicture(value); 
  92.       end;
  93.    end;
  94.  
  95.    // Description
  96.    LineNr := FindLine('histoire</TD><TD', Page, 0);
  97.    if LineNr > -1 then
  98.    begin
  99.       Line := Page.GetString(LineNr);
  100.       BeginPos := pos('histoire</TD><TD', Line);
  101.       Delete (Line, 1, BeginPos+51);
  102.       EndPos := pos('</TD></TR></TABLE>', Line);
  103.       Value := copy (Line, 1, EndPos);
  104.       value := StringReplace (Value, '<br>', #13#10); 
  105.       HTMLRemoveTags(Value);
  106.       HTMLDecode(Value);
  107.       Delete(Line, 1, EndPos);
  108.       SetField(fieldDescription, Value);
  109.    end;
  110.       
  111.    // Titre
  112.    LineNr := FindLine('>Titre</TD><TD', Page, 0);
  113.    if LineNr > -1 then
  114.    begin
  115.       Line := Page.GetString(LineNr);
  116.       BeginPos := pos('>Titre</TD><TD', Line);
  117.       Delete (Line, 1, BeginPos+49);
  118.       EndPos := pos('</TD></TR>', Line);
  119.       Value := copy(Line, 1, EndPos-1);
  120.       Value := AnsiUpFirstLetter(AnsiLowerCase(trim(Value)));
  121.       SetField(fieldTranslatedTitle, Value);
  122.    end;
  123.    
  124.    // Acteurs
  125.    LineNr := FindLine('>Acteurs</TD>', Page, 0);
  126.    if LineNr > -1 then
  127.    begin
  128.       Line := Page.GetString(LineNr);
  129.       BeginPos := Pos('>Acteurs</TD>', Line);
  130.       Delete (Line, 1, BeginPos+51);
  131.       EndPos := pos('</TD></TR>', Line);
  132.       Value := copy(Line, 1, EndPos-1);
  133.       SetField(fieldActors, Value);
  134.    end;
  135.    
  136.    // RΘalisateur
  137.    LineNr := FindLine('>RΘalisateur</TD>', Page, 0);
  138.    if LineNr > -1 then
  139.    begin
  140.       Line := Page.GetString(LineNr);
  141.       BeginPos := Pos('>RΘalisateur</TD>', Line);
  142.       Delete (Line, 1, BeginPos+55);
  143.       EndPos := pos('</TD></TR>', Line);
  144.       Value := copy(Line, 1, EndPos-1);
  145.       SetField(fieldDirector, Value);
  146.    end;
  147.    
  148.    //DurΘe  : format 2 h 20 ou 1h55 min ...
  149.    LineNr := FindLine('>DurΘe</DIV>', Page, 0);
  150.    if LineNr > -1 then
  151.    begin
  152.       Line := Page.GetString(LineNr);
  153.       BeginPos := Pos('>DurΘe</DIV>', Line);
  154.       Delete (Line, 1, BeginPos+55);
  155.       EndPos := pos('</TD></TR>', Line);
  156.       Value := copy(Line, 1, EndPos-1);
  157.       BeginPos := pos('h', value);
  158.       if (BeginPos > 0) then
  159.       begin
  160.          value := StringReplace (Value, 'min', #32); 
  161.          value := StringReplace (Value, 'mn', #32); 
  162.            value2 := copy(Value, 1, BeginPos-1);
  163.          valeur := StrToInt(trim(value2), 10)*60;
  164.          value2 := copy(value, BeginPos+1, 10);
  165.          valeur := valeur + StrToInt(trim(value2), 10);
  166.          value := IntToStr(valeur);
  167.       end;
  168.       SetField(fieldLength, Value);
  169.    end;
  170.    
  171.    //Format Audio 
  172.    LineNr := FindLine('>Le son</DIV>', Page, 0);
  173.    if LineNr > -1 then
  174.    begin
  175.       Line := Page.GetString(LineNr);
  176.       BeginPos := Pos('>Le son</DIV>', Line);
  177.       Delete (Line, 1, BeginPos+56);
  178.       EndPos := pos('</TD></TR>', Line);
  179.       Value := copy(Line, 1, EndPos-1);
  180.       SetField(fieldAudioFormat, Value); 
  181.    end;
  182.    
  183.    //Sous-Titres 
  184.    LineNr := FindLine('>Les sous-titres</DIV>', Page, 0);
  185.    if LineNr > -1 then
  186.    begin
  187.       Line := Page.GetString(LineNr);
  188.       BeginPos := Pos('>Les sous-titres</DIV>', Line);
  189.       Delete (Line, 1, BeginPos+65);
  190.       EndPos := pos('</TD></TR>', Line);
  191.       Value := copy(Line, 1, EndPos-1);
  192.       SetField(fieldSubtitles, Value); 
  193.    end;
  194.    
  195.    //Zone 
  196.    LineNr := FindLine('>Code rΘgional</DIV>', Page, 0);
  197.    if LineNr > -1 then
  198.    begin
  199.       Line := Page.GetString(LineNr);
  200.       BeginPos := Pos('>Code rΘgional</DIV>', Line);
  201.       Delete (Line, 1, BeginPos+63);
  202.       EndPos := pos('</TD></TR>', Line);
  203.       Value := copy(Line, 1, EndPos-1);
  204.       SetField(fieldVideoFormat, Value);  //α dΘcortiquer
  205.    end;
  206.    
  207.    //Langues
  208.    LineNr := FindLine('>Choix de langues</DIV>', Page, 0);
  209.    if LineNr > -1 then
  210.    begin
  211.       Line := Page.GetString(LineNr);
  212.       BeginPos := Pos('>Choix de langues</DIV>', Line);
  213.       Delete (Line, 1, BeginPos+66);
  214.       EndPos := pos('</TD></TR>', Line);
  215.       Value := copy(Line, 1, EndPos-1);
  216.       SetField(fieldLanguages, Value);  
  217.    end;
  218.    
  219.    //RΘsolution 
  220.    LineNr := FindLine('>Format image</DIV>', Page, 0);
  221.    if LineNr > -1 then
  222.    begin
  223.       Line := Page.GetString(LineNr);
  224.       BeginPos := Pos('>Format image</DIV>', Line);
  225.       Delete (Line, 1, BeginPos+62);
  226.       EndPos := pos('</TD></TR>', Line);
  227.       Value := copy(Line, 1, EndPos-1);
  228.       SetField(fieldResolution, Value);  
  229.    end;
  230.    
  231.    //Bonus 
  232.    LineNr := FindLine('>BONUS</DIV></TD>', Page, 0);
  233.    if LineNr > -1 then
  234.    begin
  235.       Value := 'Bonus :'+#13#10;
  236.       Line := Page.GetString(LineNr);
  237.       BeginPos := Pos('>BONUS</DIV></TD>', Line);
  238.       Delete (Line, 1, BeginPos+55);
  239.       EndPos := pos('</TD></TR>', Line);
  240.       Value := value + copy(Line, 1, EndPos-1);
  241.       value := StringReplace (Value, '<br>', #13#10); 
  242.       SetField(fieldComments, Value);  
  243.    end;
  244.  
  245.    //DisplayResults;
  246. end;
  247.  
  248. procedure AddMoviesTitles(Page: TStringList; var LineNr: Integer);
  249. var
  250.   Line: string;
  251.   MovieTitle, MovieAddress: string;
  252.   StartPos: Integer;
  253.   EndPos: Integer;
  254.   LastLine: Integer;
  255.  
  256. begin
  257.    repeat
  258.       Line := Page.GetString(LineNr);
  259.       StartPos := pos('bgcolor="#c50000"><A target="fich_prod"', Line);
  260.       if StartPos > 0 then 
  261.       begin
  262.          StartPos := pos('href="http://www.cdiscount.com', Line);
  263.          EndPos := pos('navid=104">', Line);
  264.          MovieAddress := copy(Line, StartPos+6, EndPos-StartPos+3);
  265.          Delete(Line, 1, EndPos+10);
  266.          EndPos := Pos ('</A></TD>', Line);
  267.          MovieTitle := copy(Line, 1, EndPos-1);
  268.          HTMLDecode(MovieAddress);
  269.          HTMLDecode(Movietitle);
  270.          PickTreeAdd(MovieTitle, MovieAddress);
  271.       end; 
  272.       LineNr := LineNr + 1;
  273.    until (LineNR > Page.count)
  274. {   if (pos('« Page précédente</a>', Line) > 0) then
  275.    begin
  276.       StartPos := pos('<a href="', Line);
  277.       EndPos :=     pos('" class="roll">« Page', Line);
  278.       PickTreeAdd('... << RΘsultats prΘcΘdents', 'http://www.alapage.com' + copy (Line, StartPos+9, Endpos-StartPos-9));
  279.    end;
  280.    if (pos('Page suivante »</DIV>', Line) > 0) then
  281.    begin
  282.       StartPos := pos('|  <A href="', Line);
  283.       EndPos :=     pos('" class="roll">Page suivante ', Line);
  284.       PickTreeAdd('RΘsultats suivants >> ...', 'http://www.alapage.com' + copy (Line, StartPos+22, Endpos-StartPos-22));
  285.    end;}
  286. end;
  287.  
  288. procedure AnalyzePage(Address: string);
  289. var
  290.   Page: TStringList;
  291.   LineNr: Integer;
  292.   Line : String;
  293.   StartPos, EndPos : integer;
  294.   Adr : String;
  295. begin
  296.   Page := TStringList.Create;
  297.   Page.Text := GetPage(Address);
  298.  
  299.   PickTreeClear;
  300.   LineNr := 0;
  301.   LineNr := FindLine('rΘsultats correspondent<BR>', Page, LineNr); // trouvΘ plusieurs rΘponses
  302.   if LineNr > -1 then
  303.   begin
  304.        Line := Page.GetString(LineNr);
  305.        StartPos := pos ('"center"><B>', Line);
  306.        EndPos := pos(' rΘsultats correspondent<BR>', Line);
  307.        PickTreeAdd(copy (Line, StartPos+12, EndPos-StartPos-12)+' Films TrouvΘs pour ' + MovieName + ' :', '');
  308.        AddMoviesTitles(Page, LineNr);
  309.        if PickTreeExec(Address) then
  310.           AnalyzePage(Address);
  311.   end
  312.   else
  313.      if (pos('1 rΘsultat correspond', Page.Text) > 0) then
  314.      begin
  315.         LineNr := FindLine('1 rΘsultat correspond', Page, LineNr); // trouvΘ 1 rΘponse
  316.         Line := Page.GetString(LineNr);
  317.         StartPos := pos('bgcolor="#c50000"><A target="fich_prod"', Line);
  318.         if StartPos > 0 then 
  319.         begin
  320.            StartPos := pos('href="http://www.cdiscount.com', Line);
  321.            EndPos := pos('navid=104">', Line);
  322.            Adr := copy(Line, StartPos+6, EndPos-StartPos+3);
  323.            HTMLDecode(Adr);
  324.            AnalyzePage(Adr);
  325.         end; 
  326.      end
  327.      else
  328.      begin
  329.         if ( pos('fiche/fiche_produit.gif"', Page.Text) > 0) then
  330.         begin
  331.            SetField(fieldURL, Address);
  332.            AnalyzeMoviePage(Page)
  333.         end;
  334.      end;
  335.  
  336.   Page.Free;
  337.  
  338. end;
  339.  
  340. begin
  341.   if CheckVersion(3,5,0) then
  342.   begin
  343.     MovieName := GetField(fieldTranslatedTitle);
  344.     if MovieName = '' then
  345.       MovieName := GetField(fieldOriginalTitle);
  346.  
  347.     if Input('CDiscount.com Import', 'Entrer le titre du film :', MovieName) then
  348.     begin
  349.        AnalyzePage('http://www.cdiscount.com/newmag/mag_dvd/list_prod_resultat_sinequa.asp?p_StrSearch='+UrlEncode(MovieName)+'&mscssid=031016203459XQGJXIBLJFBWVWL13346&refer=&REFERER_SURFEUR=&keyid=33203623');
  350.     end;
  351.   end 
  352.   else
  353.       ShowMessage('Ce script requiert une version plus rΘcente de Ant Movie Catalog (au moins la version 3.5.0)');
  354. end.
  355.